package com.tac.service.wms.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.wms.VehicleDispatchDao;
import com.tac.pojo.wms.VehicleDispatch;
import com.tac.service.wms.VehicleDispatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VehicleDispatchServiceImpl implements VehicleDispatchService {

    @Autowired
    private VehicleDispatchDao vehicleDispatchDao;

    // 查询列表
    public Result<PageInfo<VehicleDispatch>> getList(Integer pageNum, Integer pageSize, String documentNumber, String shipmentNo) {
        PageHelper.startPage(pageNum, pageSize);
        List<VehicleDispatch> list = vehicleDispatchDao.getList(documentNumber, shipmentNo);
        PageInfo<VehicleDispatch> pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo);
    }

    // 添加
    public Result insert(VehicleDispatch vehicleDispatch) {
        Integer count = vehicleDispatchDao.insert(vehicleDispatch);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("添加失败");
        }
    }

    // 更新
    public Result update(VehicleDispatch vehicleDispatch) {
        Integer count = vehicleDispatchDao.update(vehicleDispatch);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("更新失败");
        }
    }

    // 删除
    public Result delete(List<Integer> ids) {
        Integer count = vehicleDispatchDao.delete(ids);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("删除失败");
        }
    }
}

